﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace THenu.BasicKnowledge
{
    public class Person
    {
        public Person() { }
        public Person(string name, int age, Sex sex, LocoDirection direction)
        {
            Name = name;
            Age = age;
            Sex = sex;
            Direction = direction;
        }
        public String Name { get; set; }

        public int Age { get; set; }

        public Sex Sex { get; set; }

        public override string ToString()
        {
            return string.Format(string.Format("Name : {0} \t Age :{1} \t Sex :{2}\t Direction ：{3}", Name, Age, Sex.SexString(), Direction));
        }
        public LocoDirection Direction { get; set; }

    }
    public enum Sex : ushort
    {
        Unknow = 1,
        Male = 3,
        Female = 2
    }
    /// <summary>
    /// 提供方便获取字符串表示的静态扩展方法
    /// </summary>
    public static class SexExt
    {
        public static string SexString(this Sex sex)
        {
            if (sex == Sex.Female)
                return "女";
            if (sex == Sex.Male)
                return "男";

            return "未知";
        }
    }
    /// <summary>
    /// 实现比较器的接口类
    /// </summary>
    public class ISexComparer : IComparer<Sex>
    {
        private Sex prioritized;

        public ISexComparer(Sex sex = Sex.Female)
        {
            // TODO: Complete member initialization
            this.prioritized = sex;
        }

        public int Compare(Sex x, Sex y)
        {

            if (x != y)
            {
                if (x == Sex.Female)
                    return -1;
                else if (y == Sex.Female)
                    return 1;
            }

            return (int)x - (int)y;
        }
    }
}
